package com.isoftstone.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.isoftstone.entity.Menu;
import com.isoftstone.entity.Role;
import com.isoftstone.service.MenuService;
import com.isoftstone.service.RoleService;



@Controller
@RequestMapping("menus")
public class MenuController {
	@Autowired
	private MenuService menuService;

	
	@RequestMapping("menuList")
	public String getAllMenus(ModelMap modelMap){
	// TODO Auto-generated method stub
		List<Menu> list = menuService.getAllMenuList();
		modelMap.addAttribute("menuList",list);
		return "MenuList";		
	}
	@RequestMapping("insertMenu")
	@ResponseBody
	public boolean insertMenu(String menuId,String menuName,String parentId,String menuUrl){
			Menu menu=new Menu();
			menu.setMenuId(menuId);
			menu.setMenuName(menuName);
			menu.setParentId(parentId);
			menu.setMenuUrl(menuUrl);
			boolean flag = menuService.insertMenu(menu);
			return flag;	
	}
	@RequestMapping("deleteMenu")
	@ResponseBody
	public boolean deletMenu(String menuId){
		boolean flag = menuService.deleteMenu(menuId);
		return flag;		
	}
	@RequestMapping("getMenuByMenuId")
	@ResponseBody
	public Menu getMenuByMenuId(String menuId){
		Menu menu = menuService.getMenuByMenuId(menuId);
		System.out.print(menu);
		return menu;
	}
	@RequestMapping("editMenu")
	@ResponseBody
	public boolean editUser(String menuId,String menuName,String parentId,String menuUrl){
			Menu menu=new Menu();
			menu.setMenuId(menuId);
			menu.setMenuName(menuName);
			menu.setParentId(parentId);
			menu.setMenuUrl(menuUrl);
			boolean flag = menuService.editMenu(menu);
			return flag;		
	}
}
